﻿@using RooHui.Infrastructure.Entities.Enum
@{
    ViewBag.Title = "InvestmentDetail";
    Layout = "~/Views/Shared/_Member.cshtml";
    RooHui.Portal.Biz.Model.OrderDetailModel order = ViewBag.OrderDetail;
    List<IGrouping<DateTime, RooHui.Portal.Biz.Model.PayBackItemModel>> data = ViewBag.Plan;
}
@section head{
    <link rel="stylesheet" type="text/css" href="/content/plugins/fancybox/jquery.fancybox-1.3.4.css" />
    <style type="text/css">
        table.project tr td.title
        {
            width: 25%;
            text-align: right;
            font-size: 16px;
            color: #666;
        }
        table.project tr td.filed
        {
            width: 25%;
            text-align: right;
            font-size: 18px;
        }
        .wall
        {
            padding: 10px;
            border: 1px solid #e3e3e3;
            text-shadow: 0 1px 0 #fff;
            border-radius: 4px;
            -webkit-border-radius: 4px;
            -moz-border-radius: 4px;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -ms-box-sizing: border-box;
        }
        hr
        {
            margin: 10px 0;
        }
    </style>
}
<div class="container" style="padding-top: 20px;">
    <div class="bg-light wall">
        <div class="row-fluid">
            <div class="span8">
                <a href="javascript:;" class="blue" style="font-size: 24px;">@order.ProductName @order.ProjectTitle</a>
                <span style="color: #777; font-size: 12px;">项目编码：@order.ProjectCode</span><br />
                项目融资金额：<span style="color: #e86e00;">￥ @(Math.Round(order.ProjectFinancing / 10000, 2))
                    万元</span> ， 还需融资额：<span style="color: #3498DB;">￥
                        @(Math.Round(order.RemainFinancing / 10000, 2))
                        万元</span>
                <hr />
                <table class="project" style="width: 90%;">
                    <tr>
                        <td class="title">
                            预期年化利率：
                        </td>
                        <td class="filed">
                            <span class="poptag" style="border-bottom: 1px dashed #333; color: #e86e00;">
                                @(order.Policies.FirstOrDefault(c => !c.IsAttach).Rate)%
                                @if (order.Policies.Any(c => c.IsAttach && c.AddType == PolicyAddType.Award))
                                {
                                    @: + 奖励
                                }
                            </span>
                        </td>
                        <td class="title">
                            担保公司：
                        </td>
                        <td class="filed">
                            <img style="width:20px;height:20px;" alt="@order.GuaranteeName" src="@order.GuaranteeLogo">
                            @order.GuaranteeName
                        </td>
                    </tr>
                    <tr>
                        <td class="title">
                            获取收益方式：
                        </td>
                        <td class="filed">
                            <span style="border-bottom: 1px dashed #333;">@order.Policies.FirstOrDefault(c => !c.IsAttach).BalanceType.Mapping()</span>
                        </td>
                        <td class="title">
                            融资期限：
                        </td>
                        <td class="filed">
                            @(order.ProjectCycleAmount)
                            期&nbsp;&nbsp;&nbsp;(@order.Policies.FirstOrDefault(c => !c.IsAttach).Duration
                            @(order.Policies.FirstOrDefault(c => !c.IsAttach).DurationType.Mapping())/期)
                        </td>
                    </tr>
                    <tr>
                        <td class="title">
                            手续费：
                        </td>
                        <td class="filed">
                            0.00 元
                        </td>
                        <td class="title">
                            @(((int)order.ProjectStatus < (int)ProjectStatus.Repayment) ? "(预计)" : "")起息日：
                        </td>
                        <td class="filed">@order.ProjectBeginDate.ToString("yyyy-MM-dd")
                        </td>
                    </tr>
                    <tr>
                        <td class="title">
                            融资进度：
                        </td>
                        <td colspan="3">
                            @{
                                var percent = (int)(((order.ProjectFinancing - order.RemainFinancing) / order.ProjectFinancing) * 100);
                                var progressStyle = percent <= 50 ? "progress-info" : percent < 100 ? "progress-warning" : "progress-success";
                            }
                            <div class="progress @progressStyle progress-striped" style="margin:0;">
                                <div class="bar" style="width: @percent%">
                                </div>
                            </div>
                        </td>
                    </tr>
                </table>
                <hr />
                <div class="row-fluid">
                    @if (order.Policies.Any(c => c.IsAttach && c.AddType == PolicyAddType.Award))
                    {
                        <div class="span5">
                            <ul>
                                <li><strong style="color: Red; font-size: 20px;">奖励：</strong></li>
                                @{
                        var policies = order.Policies.Where(c => c.IsAttach).ToList();
                        foreach (var policy in policies)
                        {
                            if (policy.AddType == PolicyAddType.Award)
                            {
                                    <li><strong style="color: Red;">额外追加 @policy.Rate @(policy.SettlementType == SettlementType.Proportion ? "% 年化收益率" : "固定收益")
                                        (@policy.CycleAmount 期 @policy.Duration @policy.DurationType.Mapping()/期)</strong></li>
                            }
                        }
                                }
                            </ul>
                        </div>
                    }
                    @if (order.Policies.Any(c => c.IsAttach && c.AddType == PolicyAddType.Promotion))
                    {
                        <div class="span7">
                            <ul>
                                <li><strong style="color: Green; font-size: 20px;">享受促销：</strong></li>
                                @{
                        var policies = order.Policies.Where(c => c.IsAttach).ToList();
                        foreach (var policy in policies)
                        {
                            if (policy.AddType == PolicyAddType.Promotion)
                            {
                                    <li><strong style="color: Green;">额外追加 @policy.Rate @(policy.SettlementType == SettlementType.Proportion ? "% 年化收益率" : "固定收益")
                                        (@policy.CycleAmount 期 @policy.Duration @policy.DurationType.Mapping()/期) </strong>
                                    </li>
                            }
                        }
                                }
                            </ul>
                        </div>}
                </div>
            </div>
            <div class="span4">
                <div class="headline headline-md">
                    <h2>
                        相关资料</h2>
                    <ul class="list-unstyled blog-photos" style="margin: 10px 0;">
                        @{
                            foreach (var item in order.Resources)
                            {
                                if (item.PrivateLevel == PrivateLevel.Public ||
                                    (item.PrivateLevel == PrivateLevel.MemberOnly && HttpContext.Current.User.Identity.IsAuthenticated))
                                {
                            <li><a class="contract" href="@item.Path" title="@item.Name">
                                <img class="hover-effect" alt="@item.Name" src="@item.Path" /></a></li>
                                }
                            }
                        }
                    </ul>
                </div>
            </div>
        </div>
    </div>
    <div class="row-fluid">
        <div class="span12">
            <div class="wall" style="margin-top: 10px; min-height: 220px;">
                <h3>
                    您在本项目的投资详情</h3>
                <hr />
                @{
                    List<RooHui.Portal.Biz.Model.ProjectInvestModel> investment = order.ProjectInvests;
                }
                <table class="table table-bordered">
                    <tr>
                        <td rowspan="@(investment.Count + 1)" width="30%">
                            您在本项目共投资：
                        </td>
                        <td colspan="2">
                            合计投入：￥ @(investment.Sum(c => c.InvestMentAmount)) 元 <br />
                        </td>
                    </tr>
                    @foreach (var i in investment)
                    {
                        <tr>
                            <td colspan="2">
                                于 @i.RecordDate.ToString("yyyy.MM.dd HH:mm") 投资 @i.InvestMentAmount.ToString("F2")
                                元
                            </td>
                        </tr>
                    }
                    <tr>
                        <td>
                            收益方式：
                        </td>
                        <td colspan="2">
                            <span style="border-bottom: 1px dashed #333;">@order.Policies.FirstOrDefault(c => !c.IsAttach).BalanceType.Mapping()</span>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            合计收益：
                        </td>
                        <td>
                            <strong style="color: #e86e00; font-size: 20px; ">￥ @data.Sum(c => c.Sum(i => i.Value)) 元</strong>
                        </td>
                    </tr>
                    <tr>
                        <td>@(((int)order.ProjectStatus < (int)ProjectStatus.Repayment) ? "(预计)" : "")起息日：
                        </td>
                        <td colspan="2">
                            @order.ProjectBeginDate.ToString("yyyy-MM-dd")
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <strong>您的收益计划 （￥ @(investment.Sum(c => c.InvestMentAmount))）：</strong>
                        </td>
                    </tr>
                    @{
                        foreach (var item in data)
                        {
                            for (int i = 0, len = item.Count(); i < len; i++)
                            {
                                var paybackItem = item.ToList();
                        <tr>
                            @if (i == 0)
                            {
                                <td rowspan="@paybackItem.Count()">@paybackItem[i].PayBackDate.ToString("yyyy-MM-dd")
                                </td>
                            }
                            <td>
                                @if (paybackItem[i].AddType == PolicyAddType.Promotion)
                                {
                                    <strong style="color: green">[促销]</strong>
                                }
                                else if (paybackItem[i].AddType == PolicyAddType.Award)
                                {
                                    <strong style="color: red">[奖励]</strong>
                                }
                                @paybackItem[i].Name
                            </td>
                            <td>
                                ￥ @paybackItem[i].Value（元）
                            </td>
                        </tr> 
                            }
                        }
                    }
                    <tr>
                        <td>
                            &nbsp;
                        </td>
                        <td colspan="2" style="color: #e86e00; font-size: 20px; text-align: right;">
                            <strong>合计收益： ￥ @data.Sum(c => c.Sum(i => i.Value)) 元</strong>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </div>
</div>
@section scripts{
    <script type="text/javascript" src="/content/plugins/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
    <script type="text/javascript">
        $(function () {
            $('.contract').fancybox();
            $('#labinvest').addClass('active');
        });
    </script>
}
